# 删除链表中等于给定值 val 的所有节点。
#
#  示例:
#
#  输入: 1->2->6->3->4->5->6, val = 6
# 输出: 1->2->3->4->5
#
#  Related Topics 链表
#  👍 435 👎 0


# leetcode submit region begin(Prohibit modification and deletion)
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

# todo 搞懂，熟练 ，哨兵节点
from myself.listnode import ListNode


class Solution:

    def removeElements(self, head: ListNode, val: int) -> ListNode:

        sential = ListNode(0)
        sential.next = head

        prev, curr = sential, head

        while curr:
            if curr.val == val:
                prev.next = curr.next

            else:
                prev = curr

            curr = curr.next

        return sential.next

        # leetcode submit region end(Prohibit modification and deletion)
